﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ExcelAddIn1
{
    public partial class UserControl1 : UserControl
    {
        private DebugOutputModel _debugModel;
        private BindingSource _bindingSource;
        public UserControl1()
        {
            InitializeComponent();
            SetupDataBinding();
            SetupDebugRedirect();
        }

        private void SetupDataBinding()
        {
            _debugModel = new DebugOutputModel();
            _bindingSource = new BindingSource();
            _bindingSource.DataSource = _debugModel;

            // 绑定TextBox到DebugOutput属性
            this.textBox1.DataBindings.Add("Text", _bindingSource, "DebugOutput",
                false, DataSourceUpdateMode.OnPropertyChanged);
        }

        private void SetupDebugRedirect()
        {
            Debug.Listeners.Add(new BindingSourceTraceListener(_debugModel));
        }

        private void UserControl1_Load(object sender, EventArgs e)
        {

        }
    }
}
